package algorithm._1_Array._1BinarySearch;

public class MyBinarySearch {

    public static int binarySearch(Comparable[] arr,Comparable target){

        int l =0;
        int r = arr.length-1;


        while (l<=r){
                int mid = (l+r)/2;
               if (arr[mid].compareTo(target)==0)
                return mid;
               if (arr[mid].compareTo(target)<0)
                   l=mid+1;
            if (arr[mid].compareTo(target)>0)
                    r=mid-1;
        }
        return -1;
    }

    public static int orderSearch(Comparable[] arr,Comparable target){
        for (int i = 0; i < arr.length; i++) {
            //arr[i] == target
            if (arr[i].compareTo(target) == 0)
                return i;
        }
        return -1;
    }

}
